home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
011
/
branch.arc
/
BRANCH.C
next >
Wrap
Text File
|
1986-03-14
|
5KB
|
261 lines
/*
BRANCH Version 1.0
Path Management Utility
Written by Wayne D. T. Johnson
(C) COPYRIGHT 1986 by Digital Communications Consultants, ALL RIGHTS RESERVED
BRANCH is the copyrighted property of Digital Communications Consultants.
Yo⌡ arσ granteΣ ß limiteΣ licensσ t∩ usσ BRANCH¼ anΣ t∩ cop∙ i⌠ anΣ
distristribute it, provided that the following conditions are met:
1) BRANCH may not be sold, however a nominal distribution fee may be charged
to cover media cost, shipping and/or handling.
2) All copies of this program shall contain this notice.
3) All derivatives of the original code (both source, object and executable
remain the property of Digital Communications Consultants, and are bound
by this license.
4) Digital Communications Consultants has tested the original version of
BRANCH, however, in no eveny will Digital Communications Consultants
be liable for any damages caused by this program, or its derivatives.
Any voluntary contributions for the use of this program will be
appreciated, and should be sent to:
Wayne D. T. Johnson
Digital Communications Consultants
3947 Penn Ave No.
Minneapolis, MN 55412
*/
#include "stdio.h"
#include "dos.h"
extern int errno;
extern int _oserr;
#define TRUE 1
#define FALSE 0
typedef struct FILE_ENT
{
char r1[21];
char attr;
#define ATTR_DIR 0x10
struct
{
unsigned hh : 5;
unsigned mm : 6;
unsigned ss : 5;
} time;
struct
{
unsigned yy : 7;
unsigned mm : 4;
unsigned dd : 5;
} date;
long size;
char pname[13];
} FILE_ENT;
main(argc,argv)
int argc;
char *argv[];
{
char name[64];
char buffer[81];
char command[81];
int i;
if (argc<2)
{
puts("format: BRANCH dos_command parameters");
exit(1);
}
/*
build command
*/
strcpy(command, argv[1]);
for (i=2; i<argc; ++i)
{
strcat(command, " ");
strcat(command, argv[i]);
}
name[0]='\\';
getdir(&name[1]);
/*
if(name[1]=='\0')
name[0]='\0';
*/
dodir(name, command);
setdir(name);
}
dodir(name, command)
char *name;
char *command;
{
char newname[64];
char lastname[64];
setdir(name);
printf("Directory: %s", name);
system(command);
lastname[0]='\0';
while (TRUE)
{
strcpy(newname, name);
if(getbranch(newname, lastname))
{
dodir(newname, command);
}
else
break;
}
}
getbranch(name, last)
char *name;
char *last;
{
FILE_ENT file;
char mask[65];
if (strlen(name)==1)
{
strcpy(mask, "\\*");
}
else
{
strcpy(mask, name);
strcat(mask, "\\*");
}
if (*last=='\0')
{
if(!getfirst(mask, &file))
return FALSE;
}
else
{
getfirst(mask, &file);
while(TRUE)
{
if (strcmp(file.pname, last)==0)
{
if (!getnext(mask, &file))
return FALSE;
break;
}
if (!getnext(mask, &file))
return FALSE;
}
}
do
{
if (file.attr&ATTR_DIR && file.pname[0]!='.')
{
if(strlen(name)!=1)
strcat(name, "\\");
strcat(name, file.pname);
strcpy(last, file.pname);
return TRUE;
}
}
while (getnext(mask, &file));
return FALSE;
}
setdir(addr)
char *addr;
{
union REGS intregs;
int flags;
intregs.h.ah=0x3b;
intregs.x.dx=(int)addr;
flags=intdos(&intregs,&intregs);
if (flags&0x0100!=0)
return FALSE;
return TRUE;
}
getdir(addr)
char *addr;
{
union REGS intregs;
int flags;
intregs.h.ah=0x47;
intregs.h.dl=0;
intregs.x.si=(int)addr;
flags=intdos(&intregs,&intregs);
if (flags&0x0100!=0)
return FALSE;
return TRUE;
}
getfirst(mask, file)
char *mask;
FILE_ENT *file;
{
union REGS intregs;
int flags;
extern int _PSP;
setdma(file);
intregs.h.ah=0x4e;
intregs.x.dx=(int)mask;
intregs.x.cx=16;
flags=intdos(&intregs,&intregs);
if (flags&0x0100!=0)
return FALSE;
return TRUE;
}
getnext(mask, file)
char *mask;
FILE_ENT *file;
{
union REGS intregs;
int flags;
extern int _PSP;
intregs.h.ah=0x4f;
flags=intdos(&intregs,&intregs);
if (flags&0x0100!=0)
return FALSE;
return TRUE;
}
setdma(addr)
char *addr;
{
union REGS intregs;
intregs.h.ah=0x1a;
intregs.x.dx=(int)addr;
intdos(&intregs,&intregs);
}